#include "cuda_util.h"
#include "cush_alloc.h"

#include <cuda.h>
#include <stdio.h>

/**
 *
 * Extracts and returns the device ptr associated with 'id' from dps
 * 
 * TODO: determine whether id should be an index or a device id?
 *			It will be in index for now
 *
 **/
cush_dbuff_t* cush_extract_ptr(cush_dbuff_t* dps, int id){

	cush_dbuff_t* ret = (cush_dbuff_t*)malloc(sizeof(cush_dbuff_t));

	cush_dp_init(ret, dps->type, 1);

	//memcpy(ret->size, &(dps->size[id]), sizeof(int));
	//memcpy(ret->offset, &(dps->offset[id]), sizeof(size_t));
	//memcpy(ret->ptr, &(dps->ptr[id]), sizeof(void**));

	ret->id[0]		= dps->id[id];
	ret->size[0]	= dps->size[id];
	ret->offset[0]	= dps->offset[id];
	//printf("Extracting device pointer %lu\n", dps->ptr[id]);
	ret->ptr[0]		= dps->ptr[id];
	
	return ret;
}

